package com.itheima.completableFuture;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @program: itheima-jdk8
 * @description:
 * @author: zhanghz001
 * @create: 2021-01-09 11:29
 **/
public class AnyOfDemo1 {
    public static void main(String[] args) {
        
        ExecutorService pool = Executors.newFixedThreadPool(100);
        
        //
        CompletableFuture<Void> future1 = CompletableFuture.runAsync(() -> {
            System.out.println(Thread.currentThread().getName());
            
        }, pool);
        CompletableFuture<Void> future2 = CompletableFuture.runAsync(() -> {
            System.out.println(Thread.currentThread().getName());
            
        }, pool);
        CompletableFuture<Void> future3 = CompletableFuture.runAsync(() -> {
            System.out.println(Thread.currentThread().getName());
            
        }, pool);
        // CompletableFuture<Void> future = CompletableFuture.allOf(future1, future2, future3);
        // // future.thenRunAsync();
        // try {
        //     System.out.println(future.get());
        // } catch (InterruptedException e) {
        //     e.printStackTrace();
        // } catch (ExecutionException e) {
        //     e.printStackTrace();
        // } finally {
        //     pool.shutdown();
        // }
        List<CompletableFuture<Void>> list = new ArrayList<>();
        list.add(future1);
        list.add(future2);
        list.add(future3);
        ;
        CompletableFuture<Object> any = CompletableFuture.anyOf(list.toArray(new CompletableFuture[]{}));
        any.thenRunAsync(() -> {
            System.out.println(Thread.currentThread().getName() + "1111");
        }, pool);
        pool.shutdown();
    }
}
